import { ElMessage } from "element-plus";
import createOssClientTemp from "./initOss.ts";
export interface OssFile {
  name: string;
  res: {
    aborted: boolean;
    keepAliveSocket: boolean;
    data: any;
    header: object;
    remoteAddress: string;
    remotePort: string;
    requestUrls: [string];
  };
  rt: number;
  size: number;
  status: number;
  timing: null;
  url: number;
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const OssUploadFile: Promise<OssFile> = async (file: any) => {
  const client = await createOssClientTemp();
  return new Promise((resolve, reject) => {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-expect-error
    client
      .put(file.name, file)
      .then((result: any) => {
        if (result.res) {
          const res = result.res;
          if (res.status === 200) {
            console.log("阿里云 oss 上传 成功", result);
            resolve(result);
          }
        }
      })
      .catch(error => {
        console.log("阿里云 oss 上传 失败", error);
        reject(error);
      });
  });
};
export default OssUploadFile;
